CREATE TABLE [dbo].[tb_Estados]
(
[idEstado] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updateEstados] ON [dbo].[tb_Estados] 
FOR UPDATE
AS
if (update(idEstado)) begin

	UPDATE tb_Edificios
	SET EstadoGeneral = (SELECT idEstado from inserted)
	WHERE EstadoGeneral in (SELECT idEstado from deleted)

	UPDATE tb_MueblesYEquipos
	SET EstadoGeneral = (SELECT idEstado from inserted)
	WHERE EstadoGeneral in (SELECT idEstado from deleted)	

	UPDATE tb_Instalaciones
	SET EstadoGeneral = (SELECT idEstado from inserted)
	WHERE EstadoGeneral in (SELECT idEstado from deleted)	

	UPDATE tb_Inspecciones
	SET Estado = (SELECT idEstado from inserted)
	WHERE Estado in (SELECT idEstado from deleted)

	UPDATE tb_Reparaciones
	SET EstadoFinal = (SELECT idEstado from inserted)
	WHERE EstadoFinal in (SELECT idEstado from deleted)
end
GO
ALTER TABLE [dbo].[tb_Estados] ADD CONSTRAINT [PK_tb_Estados] PRIMARY KEY NONCLUSTERED  ([idEstado]) ON [PRIMARY]
GO
